﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Zeus.Thunder.Core;

namespace SharpTrainer.Delegates
{
    interface ITransformer
    {
        int Transform(int x);
    }

    class Squarer : ITransformer
    {
        public int Transform(int x) { return x * x; }
    }

    class Cuber : ITransformer
    {
        public int Transform(int x) { return x * x * x; }
    }

    class Util3
    {
        public static void TransformAll (int[] values, ITransformer t)
        {
            for (int i = 0; i < values.Length; i++)
                values[i] = t.Transform (values[i]);
        }
    }

    class ReplaceDelegateWithInterface : ITestCase
    {
        public void Run()
        {
            int[] values = { 1, 2, 3 };
            int[] values2 = { 1, 2, 3 };

            Util3.TransformAll(values, new Squarer());
            Console.WriteLine("Square Values:");
            foreach (int i in values)
                Console.WriteLine(i);

            Console.WriteLine("------------------------------");

            Util3.TransformAll(values2, new Cuber());
            Console.WriteLine("Cubic Values:");
            foreach (int i in values2)
                Console.WriteLine(i);
        }
    }
}
